/**
 * 住户管理API接口
 * @author Wu.Liang
 * @date 2025-07-28
 */
import api from '@/api/request'
import type { 
  Resident, 
  ResidentHouseholdAddDTO 
} from '@/types/resident'

// 住户管理API
export const residentApi = {
  // 获取住户列表
  getResidentList(params: any) {
    return api.get('/api/region/resident', { params })
  },

  // 根据姓名查询住户
  getResidentsByRealName(realName: string) {
    return api.get(`/api/region/resident/name/${realName}`)
  },

  // 根据用户ID获取住户信息
  getResidentsByUserId(userId: number) {
    return api.get(`/api/region/resident/user/${userId}`)
  },

  // 根据住户ID获取住户信息
  getResidentById(residentId: number) {
    return api.get(`/api/region/resident/${residentId}`)
  },

  // 新增住户信息
  addResident(data: any) {
    return api.post('/api/region/resident', data)
  },

  // 更新住户信息
  updateResident(id: number, data: Partial<Resident>) {
    return api.put(`/api/region/resident/${id}`, data)
  },

  // 删除住户信息
  deleteResident(id: number) {
    return api.delete(`/api/region/resident/${id}`)
  },

  // 新增住户到房户
  addResidentToHousehold(householdId: number, data: ResidentHouseholdAddDTO) {
    return api.post(`/api/region/resident-households/${householdId}`, data)
  },

  // 更新住户房户关联信息
  updateResidentHousehold(residentId: number, data: Partial<ResidentHouseholdAddDTO>) {
    return api.put(`/api/region/resident-households/${residentId}`, data)
  },

  // 删除住户房户关联
  deleteResidentFromHousehold(householdId: number, residentId: number) {
    return api.delete(`/api/region/resident-households/${householdId}/resident/${residentId}`)
  },

  // 获取住户详情
  getResidentDetail(residentId: number) {
    return api.get(`/api/region/residents/detail/${residentId}`)
  },

  // 获取住户统计信息
  getResidentStatistics(params?: any) {
    return api.get('/api/region/residents/statistics', { params })
  },

  // 搜索住户
  searchResidents(params: any) {
    return api.get('/api/region/residents/search', { params })
  },

  // 获取住户关系列表
  getResidentRelations(residentId: number) {
    return api.get(`/api/region/residents/${residentId}/relations`)
  },

  // 添加住户关系
  addResidentRelation(data: any) {
    return api.post('/api/region/residents/relations', data)
  },

  // 删除住户关系
  deleteResidentRelation(relationId: number) {
    return api.delete(`/api/region/residents/relations/${relationId}`)
  },

  // 根据用户ID查询家庭成员列表
  getFamilyMembersByUserId(userId: number) {
    return api.get(`/api/region/resident/user/${userId}/family`)
  },

  // 根据用户ID查询租客列表
  getTenantsByUserId(userId: number) {
    return api.get(`/api/region/resident/user/${userId}/tenants`)
  }
} 